package com.firewolf.rabbitmq;

import java.io.IOException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmListener;
import com.rabbitmq.client.Connection;

import utils.ConnectionUtils;

public class Sender {
	
	private static final String QUEUE_NAME = "queue_confirmqueue_async";
	public static void main(String[] args) throws Exception {
		
		Connection connection = ConnectionUtils.getMQConnection();
		
		Channel channel = connection.createChannel();
		
		channel.queueDeclare(QUEUE_NAME, false, false,false, null);
		
		
		channel.confirmSelect();
		
		channel.addConfirmListener(new ConfirmListener() {
			
			//处理失败的回执
			@Override
			public void handleNack(long deliveryTag, boolean multiple) throws IOException {
				System.err.println("处理失败："+deliveryTag);
			}
			
			//处理成功的回执
			@Override
			public void handleAck(long deliveryTag, boolean multiple) throws IOException {
				System.out.println("处理成功："+deliveryTag);
			}
		});
		String msg  = "Hello";
		for(int i =0;i<10;i++){
			long msgNO = channel.getNextPublishSeqNo();
			channel.basicPublish("", QUEUE_NAME, null, (msg+i).getBytes());
			System.out.println(msgNO);
		}
	}
}
